<?php

namespace App\Observers;

use App\Models\Posts;
use App\Models\PostsLike;

class PostsLikeObserver
{

    /**
     * 监听创建前事件.
     *
     * @param PostsLike $model
     * @return void
     */
    public function creating(PostsLike $model)
    {

    }

    /**
     * 监听创建事件.
     *
     * @param PostsLike $model
     * @return void
     */
    public function created(PostsLike $model)
    {
        Posts::where('id', $model->posts_id)->increment('like_amount');
    }

    public function updating(PostsLike $model)
    {

    }

    /**
     * 监听更新后事件.
     *
     * @param PostsLike $model
     * @return void
     */
    public function updated(PostsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param PostsLike $model
     * @return void
     */
    public function deleting(PostsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param PostsLike $model
     * @return void
     */
    public function deleted(PostsLike $model)
    {
        Posts::where('id', $model->posts_id)->decrement('like_amount');
    }

}
